<template>
<div class="page-container">
    <!--工具栏-->
    <div class="toolbar">
        <el-form :inline="true" :model="filters" :size="size">
            <el-row class="search-input">
                <el-form-item label="名称搜索：">
                    <el-input v-model="filters.name" clearable placeholder="名称搜索"></el-input>
                </el-form-item>
                <el-form-item label="级别：">
                    <el-select clearable v-model="filters.level">
                        <el-option label="全部" value="">全部</el-option>
                        <el-option label="省" value="0">省</el-option>
                        <el-option label="市" value="1">市</el-option>
                        <el-option label="县" value="2">县</el-option>
                    </el-select>
                </el-form-item>
            </el-row>
            <el-row class="search-button">
                <el-form-item>
                    <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="findPage(filters)" />
                </el-form-item>
                <el-form-item>
                    <kt-button icon="fa fa-refresh" :label="$t('action.reset')" @click="reset" type="primary" />
                </el-form-item>
            </el-row>
            <el-form-item class="t_r w100">
                <el-button-group>
                    <el-tooltip content="刷新" placement="top">
                        <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
                    </el-tooltip>
                    <el-tooltip content="列显示" placement="top">
                        <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
                    </el-tooltip>
                    <!-- <el-tooltip content="导出" placement="top">

<el-button icon="fa fa-file-excel-o"  @click="downloadExcel" ></el-button>

</el-tooltip>-->
                </el-button-group>
            </el-form-item>
            <!--表格显示列界面-->
            <table-column-filter-dialog ref="tableColumnFilterDialog" :columns="columns" @handleFilterColumns="handleFilterColumns"></table-column-filter-dialog>
        </el-form>
    </div>
    <!--表格内容栏-->
    <jic-table :height="350" :data="pageResult" :columns="filterColumns" @findPage="findPage" ref="JicTable" :showOperation="false" :showBatchDelete="false" :showSelection="false"></jic-table>
</div>
</template>

<script src="//unpkg.com/element-ui@2.12.0/lib/index.js"></script><script>
import PopupTreeInput from "@/components/PopupTreeInput";
import JicTable from "@/views/Core/JicTable";
import KtButton from "@/views/Core/KtButton";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import {
    format
} from "@/utils/datetime";
import axios from "axios";
export default {
    components: {
        PopupTreeInput,
        JicTable,
        KtButton,
        TableColumnFilterDialog
    },
    data() {
        return {
            imgUpload: this.utils.getUpLoadHost(),
            size: "small",
            document_license: "",
            filters: {
                name: ""
            },

            imgs: "",
            fileList: {},
            columns: [],
            shoplist: [],
            filterColumns: [],
            selected: "",
            pageRequest: {
                pageNum: 1,
                pageSize: 10
            },
            pageResult: {},
            dialogImageUrl: "",

            operation: false, // true:新增, false:编辑
            dialogVisible: false, // 新增编辑界面是否显示
            editLoading: false,
            printPage: false,
            dataFormRules: {}
        };
    },
    methods: {
        // 获取分页数据
        findPage: function (data) {
            /**
             * 子组件传过来的分页参数
             * data.start 当前页
             * data.limit 当前页总条数
             * */

            if (data != null && data.start != null) {
                if (data.start != null) {
                    this.pageRequest.pageNum = data.start;
                }
                if (data.limit != null) {
                    this.pageRequest.pageSize = data.limit;
                }
            }

            let this_ = this;
            if (this_.filters == undefined || this_.filters == null) {
                this_.filters = {};
            }
            this_.filters.start = this.pageRequest.pageNum;
            this_.filters.limit = this.pageRequest.pageSize;
            this.utils.request.getSysProvinceCityPageList(this_.filters, function (
                res
            ) {
                this_.$refs.JicTable.findPage({
                    content: res.data.rows,
                    total: res.data.total
                });
            });
        },

        //列表下载
        downloadExcel() {
            this.$confirm("确定下载列表文件?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                })
                .then(() => {
                    let filename = "省市县列表";
                    this.$refs.CyTable.exportData(
                        this.filters,
                        this.filterColumns,
                        filename
                    );
                })
                .catch(() => {});
        },

        reset: function () {
            this.filters = {};
            this.findPage();
        },

        // 时间格式化
        dateFormat: function (row, column, cellValue, index) {
            return format(row[column.property]);
        },

        // 处理表格列过滤显示
        displayFilterColumnsDialog: function () {
            this.$refs.tableColumnFilterDialog.setDialogVisible(true);
        },
        // 处理表格列过滤显示
        handleFilterColumns: function (data) {
            this.filterColumns = data.filterColumns;
            this.$refs.tableColumnFilterDialog.setDialogVisible(false);
        },
        // 处理表格列过滤显示
        initColumns: function () {
            this.columns = [
                //{prop:"id", label:"ID", minWidth:50},
                {
                    prop: "id",
                    label: "ID",
                    minWidth: 120
                },
                {
                    prop: "name",
                    label: "名称",
                    minWidth: 120
                },
                // {prop:"pname", label:"上级名称", minWidth:120},
                {
                    prop: "level",
                    label: "级别",
                    minWidth: 120,
                    formatter: this.level
                },
                {
                    prop: "code",
                    label: "code",
                    minWidth: 120
                },
                {
                    prop: "zipCode",
                    label: "邮政编码",
                    minWidth: 120
                },
                {
                    prop: "shortName",
                    label: "简称",
                    minWidth: 120
                },
                {
                    prop: "lng",
                    label: "纵轴",
                    minWidth: 120
                },
                {
                    prop: "lat",
                    label: "横轴",
                    minWidth: 120
                },
                {
                    prop: "createTime",
                    label: "创建时间",
                    minWidth: 120
                },
                {
                    prop: "updateTime",
                    label: "修改时间",
                    minWidth: 120
                }
            ];
            var temp = [];
            $.each(this.columns, function (key, val) {
                temp.push(val);
            });
            this.filterColumns = temp;
        },
        level: function (row, column, cellValue, index) {
            if (cellValue == 0) {
                return "省";
            } else if (cellValue == 1) {
                return "市";
            } else {
                return "县";
            }
        }
    },
    mounted() {
        this.findPage();
        this.initColumns();
    }
};
</script>

<style lang="scss" scoped>
/deep/ .el-input__inner {
    width: 200px;
}

.el-form-item--mini.el-form-item,
.el-form-item--small.el-form-item {
    margin-bottom: 10px;
}
</style>
